<?php
require (Yii::app ()->basePath . '/lib/rolling-curl/RollingCurl.php');
/**
 *
 * @author user
 * @see 用户管理
 */
class UserController extends CController {
	function actionText1() {
		$this->render ( 'text1' );
	}
	function actionText2() {
		$this->render ( 'text2' );
	}
	function actionText3() {
		$this->render ( 'text3' );
	}
	function actionText4() {
		$this->render ( 'text4' );
	}
	function actionText5() {
		$this->render ( 'text5' );
	}
	function actionText6() {
		$this->render ( 'text6' );
	}
	function actionText7() {
		$this->render ( 'text7' );
	}
	function actionText8() {
		$this->render ( 'text8' );
	}
	function actionText9() {
		$this->render ( 'text9' );
	}
	function actionText10() {
		$this->render ( 'text10' );
	}
	function actionText11() {
		$this->render ( 'text11' );
	}
	function actionText12() {
		$this->render ( 'text12' );
	}
	function actionText13() {
		$this->render ( 'text13' );
	}
	function actionText14() {
		$this->render ( 'text14' );
	}
	function actionText15() {
		$this->render ( 'text15' );
	}
	function actionText16() {
		$this->render ( 'text16' );
	}
	function actionText17() {
		$this->render ( 'text17' );
	}
	function actionText18() {
		$this->render ( 'text18' );
	}
	function actionText19() {
		$this->render ( 'text19' );
	}
	function actionText20() {
		$this->render ( 'text20' );
	}
	function actionText21() {
		$this->render ( 'text21' );
	}
	/**
	 *
	 * @see 用户管理-用户列表
	 */
	function actionList() {
		$this->render ( 'list' );
	}
	/**
	 *
	 * @see ajax 列表
	 */
	function actionAjax_list() {
		$ret = new stdClass ();
		$ret->status = 401;
		$service = new UserEntity ();
		$pg = $_GET ['page'];
		
		$where = array (
				'deleted' => 0 
		);
		$cn = $_GET ['cn'] or "";
		$ac = $_GET ['ac'] or "";
		$phone = $_GET ['phone'] or "";
		$tb = $_GET ['tb'] or "-1";
		$where = array ();
		if ($cn != "")
			$where ['company_name'] = "[code] like '%$cn%' [code]";
		if ($phone != "")
			$where ['phone'] = "[code] like '%$phone%'[code]";
		if ($ac != "")
			$where ['account'] = "[code] like '%$ac%'[code]";
			/*
		 * switch ($tb) {
		 * default :
		 * break;
		 * case "0" :
		 * $where ['type1'] = 0;
		 * break;
		 * case "1" :
		 * $where ['type1'] = 1;
		 * break;
		 * case "2" :
		 * $where ['type1'] = 1;
		 * $where ['seller_add_other_zj'] = "[code]<> '' [code]";
		 * break;
		 * case "3" :
		 * // $where ['type1'] = 1;
		 * $where ['is_audit'] = 2;
		 * break;
		 * }
		 */
		if (empty ( $pg ) || ! is_numeric ( $pg ) || $pg <= 0)
			$pg = 1;
		$list = $service->get_list ( $pg, 10, $where, array (
				'id' => 'desc' 
		) ); // 获取当前页数据
		$totalCount = $service->get_record_count ( $where ); // 获取总页数
		$page_count = 1;
		$ret->tct = $totalCount;
		if ($totalCount > 0)
			$page_count = ceil ( $totalCount / 10.0 ); // 计算总共页数
		$ret->pi = $pg;
		if ($list === false) {
			$ret->status = 500;
			$ret->data = "未找到匹配数据";
		} else {
			$ret->status = 200;
			$ret->data = $list;
			$ret->page_count = $page_count;
		}
		echo json_encode ( $ret );
	}
	
	/**
	 *
	 * @see 用户管理-用户列表-详情
	 */
	public function actionDetail() {
		if (isset ( $_GET ['id'] ) && is_numeric ( $_GET ['id'] )) {
			$id = $_GET ['id'];
			$service = new UserEntity ();
			$model = $service->get ( $id );
			if (false === $user) {
				// 参数错误
				exit ( "参数错误" );
			} else {
				$this->renderPartial ( 'detail', array (
						'model' => $model 
				) );
			}
		} else {
			// 参数错误
			exit ( "参数错误" );
		}
	}
	
	/**
	 *
	 * @see ajax 删除用户信息
	 */
	function actionAjax_delete() {
		$ret = new stdClass ();
		$ret->status = 0;
		if (Yii::app ()->user->isGuest) {
			$ret->data = "请登录";
			echo json_encode ( $ret );
			Yii::app ()->end ();
		}
		if (isset ( $_POST ['id'] ) && is_numeric ( $_POST ['id'] )) {
			$id = $_POST ['id'];
			$userService = new UserEntity ();
			$result = $userService->delete_user ( $id );
			if ($result) {
				$ret->status = 1;
			}
		}
		echo json_encode ( $ret );
	}
}

	
